<div style="clear"></div>
<div style="width: 700px; height: 23px;">
    <div class='loadding_update' id='loadding_update'></div>         
</div>

<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'form_module_checkout',
    'enableAjaxValidation' => false,
    'enableClientValidation' => true,
    'clientOptions' => array(
        'validateOnSubmit' => true,
    ),
        ));
?> 
<div class="content-box">
    <div class="content-box-header">
        <h3>Form order</h3> 
        <h3><?php echo 'Form status'; ?></h3>
        <h3><?php echo 'Form name'; ?></h3>                             
    </div> 
    <div  class="content-box-content"></div> 
    <div id="extra_box" class="tab-content default-tab">
        <div id="list-item-div">                    
            <ul class="ui-sortable" name="list-item" id="list-item-ul">                       
                <?php
                $stt = 1;
                foreach ($list_form as $lb) {
                    ?>
                    <li class="list_item_wrapper" style="display: list-item;" align="left" id="li_item_id-<?php echo $lb['form_id']; ?>" name="new-item-1">   
                        <div class="item_div_wrapper" style="min-height:20px;;" rel="0">   
                            <div style="width: 100px; float: left; text-align: center;">
                                <span id="item_order_<?php echo $lb['form_id']; ?>" ><?php echo $stt; ?></span>
                            </div>
                            <div style="float: left; margin: 0px 0px; width: 110px; text-align: center;">
                                <input <?php if ($lb['form_status'] == 1) echo 'checked="checked"' ?> type="checkbox" name="<?php echo 'cb_id_' . $lb['form_id']; ?>" value="<?php echo $lb['form_id']; ?>"><br>                          
                            </div>
                            <div style="float: left;margin-left:10px;">
                                <span class="item_name" style="color: red;"><?php echo $lb['form_name']; ?></span>                                
                            </div>                                    
                            <div style="float: right;">                                     
                            </div>
                        </div>
                        <ul class="ui-sortable" name="sub-list-ul">    
                        </ul>                                                      
                    </li>
                    <?php
                    $stt++;
                }
                ?>
            </ul>
        </div>    
    </div>    


</div>
</div>
<?php $this->endWidget(); ?> 
<script>
    $(document).ready(function() {

        $('#list-item-ul input[type="checkbox"]').each(function() {
            $(this).click(function() {
                $('#loadding_update').css({'display': 'block'});
                ajaxupdateformstatus($(this).val(), $(this).is(':checked') ? 1 : 0);

            });
        });
        $('.ui-sortable').sortable({
            update: function(event, ui) {
                var data_order = $(this).sortable("serialize");
                $('#loadding_update').css({'display': 'block'});
                var arr = data_order.split("&");
                var arr_ob = [];
                //alert(data_order);
                for (var i = 0; i < arr.length; i++)
                {
                    var arr_temp = arr[i].split("=");
                    arr_ob[i] = arr_temp[1];
                }
                setorder(arr_ob);
                $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    url: '<?php echo $this->form_change_order_url; ?>',
                    data: {YII_CSRF_TOKEN: '<?php echo Yii::app()->getRequest()->getCsrfToken(); ?>', data: data_order},
                    success: function(data) {
                        $('#loadding_update').css({'display': 'none'});
                        if (data.result == 'success') {
                            return;
                        } else {
                            alert(data.message);
                        }
                    },
                    error: function(XHR) {
                        return;
                    }
                });
            }
        });
    });
    function setorder($arr)
    {
        for (var j = 0; j < $arr.length; j++)
        {
            $('#item_order_' + $arr[j]).html(j + 1);
        }
    }
    function ajaxupdateformstatus(form_id, form_status)
    {
<?php
echo Chtml::ajax(array(
    'url' => Yii::app()->createUrl('shopping/updateformstatus'), //array('site/test'),
    'data' => array('form_id' => 'js:form_id', 'form_status' => 'js:form_status'),
    'type' => 'get',
    'success' => "function(str){
                                        successupdateformstatus(str);
                                    }"
));
?>
    }
    function successupdateformstatus(str)
    {
        // alert(str);
        $('#loadding_update').css({'display': 'none'});
    }

</script>


